package can.bishe.modules.exam.controller;

import java.util.Arrays;
import java.util.Map;

import can.bishe.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import can.bishe.modules.exam.entity.ExamOptionEntity;
import can.bishe.modules.exam.service.ExamOptionService;
import can.bishe.common.utils.PageUtils;
import can.bishe.common.utils.R;



/**
 * 选项信息
 *
 * @author can
 * @email 822024417@qq.com
 * @date 2021-04-28 23:03:48
 */
@RestController
@RequestMapping("exam/examoption")
public class ExamOptionController {
    @Autowired
    private ExamOptionService examOptionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = examOptionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{optionId}")
    public R info(@PathVariable("optionId") Long optionId){
        ExamOptionEntity examOption = examOptionService.getById(optionId);

        return R.ok().put("examOption", examOption);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ExamOptionEntity examOption){
        examOptionService.save(examOption);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ExamOptionEntity examOption){
        ValidatorUtils.validateEntity(examOption);
        examOptionService.updateById(examOption);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] optionIds){
        examOptionService.removeByIds(Arrays.asList(optionIds));

        return R.ok();
    }

}
